//
//  PlayingAlbumViewController.m
//  SuperRadio
//
//  Created by supercchome on 14/12/23.
//  Copyright (c) 2014年 三个臭皮匠. All rights reserved.
//

#import "PlayingAlbumViewController.h"
#import "PlayingAlbum.h"
#import "PlayingAlbumCell.h"
#import "NetHandler.h"

@interface PlayingAlbumViewController ()<UITableViewDataSource,UITableViewDelegate>

@property(nonatomic, retain)UITableView *tableView;
@property(nonatomic, retain)NSMutableArray *arr;
//@property(nonatomic, retain)NSMutableArray *playArr;



@end

@implementation PlayingAlbumViewController

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}

- (void)HandleData
{
    NSString *str = @"http://mobile.ximalaya.com/mobile/playlist/album?albumId=2227&device=iPhone&trackId=145772";
    [NetHandler getDataWithURL:str completion:^(NSData *data) {
       
        NSDictionary *playDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        NSMutableArray *playAlbumArr = [playDic objectForKey:@"data"];
        self.arr = [NSMutableArray array];
        for (NSMutableDictionary *playAlbumDic in playAlbumArr) {
            PlayingAlbum *playlist = [[PlayingAlbum alloc] initWithDictionary:playAlbumDic];
           [self.arr addObject:playlist];
            
            [playlist release];
        }
        
        //[self.arr addObjectsFromArray:self.playArr];
        [self.tableView reloadData];
        
        
        
        
    }];
    
    
    
    
    
    
}







- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.tableView = [[UITableView alloc]init];
    self.tableView.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
    [_tableView release];
    
    
}








- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.arr.count;
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *str = @"reuse";
    PlayingAlbumCell *cell = [tableView dequeueReusableCellWithIdentifier:str];
    if (cell == nil) {
        cell = [[[PlayingAlbumCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:str]autorelease];
    }
    PlayingAlbum *play = [self.arr objectAtIndex:indexPath.row];
    cell.playingAlbum = play;
    return cell;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
